Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy navigation area infrastructure from Gutenberg #1865

Closed
wants to merge 17 commits into from

Conversation

noisysocks
Copy link
Member

Copies navigation area infrastructure from lib/navigation.php in Gutenberg to Core.

I meant to include this #1804 but I ran out of time on Tuesday 🙂

Trac ticket: https://core.trac.wordpress.org/ticket/54337


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@noisysocks
Copy link
Member Author

@anton-vlasenko @adamziel @talldan: I'm not 100% sure how to test this. Could you please give it a whirl?

@noisysocks
Copy link
Member Author

Need to add this new addition from lib/navigation.php:

diff --git a/lib/navigation.php b/lib/navigation.php
index 8a3587ae7d..5f69152724 100644
--- a/lib/navigation.php
+++ b/lib/navigation.php
@@ -56,6 +56,14 @@ function gutenberg_register_navigation_post_type() {
 }
 add_action( 'init', 'gutenberg_register_navigation_post_type' );

+/**
+ * Disable "Post Attributes" for wp_navigation post type.
+ *
+ * The attributes are also conditionally enabled when a site has custom templates.
+ * Block Theme templates can be available for every post type.
+ */
+add_filter( 'theme_wp_navigation_templates', '__return_empty_array' );
+

return;
}

add_post_type_support( $post_type, 'editor' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this? Are not just not register support for editor, until we are ready?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We temporarily disable it in _disable_content_editor_for_navigation_post_type so that the editor doesn't appear when you edit the CPT. This re-enables it.

src/wp-admin/site-editor.php Outdated Show resolved Hide resolved
src/wp-includes/navigation-areas.php Outdated Show resolved Hide resolved
src/wp-includes/navigation-areas.php Outdated Show resolved Hide resolved
src/wp-includes/navigation-areas.php Show resolved Hide resolved
src/wp-includes/navigation-areas.php Outdated Show resolved Hide resolved
src/wp-includes/navigation-areas.php Outdated Show resolved Hide resolved
src/wp-includes/navigation-areas.php Outdated Show resolved Hide resolved
'post_content' => serialize_blocks( $parsed_blocks ),
'post_status' => $post_status,
);
$navigation_post_id = wp_insert_post( $post_data );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There NEEDs to be some error handling here. What is the database falls over and this returns a WP_Error object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should happen in this case? @talldan @adamziel

Copy link
Contributor

@adamziel adamziel Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning error here and then Error 500 from the API endpoint sounds like a sensible thing to do

src/wp-includes/navigation-areas.php Outdated Show resolved Hide resolved
src/wp-includes/default-filters.php Outdated Show resolved Hide resolved
@spacedmonkey
Copy link
Member

Unit tests seem to be failing...

Copy link
Member

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test

@noisysocks
Copy link
Member Author

noisysocks commented Nov 12, 2021

We will have to rename fse_navigation_areas in the plugin first as it is used by blocks/navigation.php which is copied from the Gutenberg repo as part of the build process. We will also have to include some migration code in the plugin when doing this rename. Let's handle this as a follow-up so that this feature exists in Beta 1 next week.

@noisysocks noisysocks closed this Nov 12, 2021
@noisysocks noisysocks deleted the add/navigation-areas branch November 12, 2021 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants